﻿// -------------------------------------------------------------------------
//    @FileName         :    NFTransAccBase.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-08-17
//    @Email			:    445267987@qq.com
//    @Module           :    NFTransAccBase
//    @Desc             :    
//
// -------------------------------------------------------------------------

#include "NFTransAccBase.h"

#include "NFOnlineService.h"
#include "NFOnlineUtil.h"
#include "NFPlayerMgr.h"
#include "NFComm/NFCore/NFTimeUtility.h"
#include "NFLogicCommon/NFScopedMessageHead.h"
#include "NFServerComm/NFServerCommon/NFIServerMessageModule.h"
#include "Session/NFSession.h"
#include "Session/NFSessionUtil.h"

NFTransAccBase::NFTransAccBase()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFTransAccBase::~NFTransAccBase()
{

}

int NFTransAccBase::CreateInit()
{
    m_iServerType = NF_ST_LOGIC_SERVER;
    m_iTableId = E_TABLE_ROLE_LIST;
    m_zoneId = 0;
    m_uin = 0;
    return 0;
}

int NFTransAccBase::ResumeInit()
{
    return 0;
}

int NFTransAccBase::Init(NFSession* pSession, uint32_t cmd, uint32_t csSeq)
{
    CHECK_NULL(0, pSession);
    SetClientSession(pSession);

    m_stCSMsgHeadReq.m_iMsgID = (proto_ff::Proto_CS_CMD)cmd;
    m_stCSMsgHeadReq.m_iSeqCS = csSeq;

    m_stCSMsgHeadReq.m_iSeqCS = NFScopedMessageHead::GetStackRequestSeq(m_iClientSessionID, m_stCSMsgHeadReq.m_iSeqCS);
    return 0;
}

int NFTransAccBase::SetClientSession(NFSession* pSession)
{
    if (pSession)
    {
        m_iClientSessionID = pSession->GetGlobalId();
        m_ullRoleId = pSession->GetUIN();
        m_zoneId = pSession->GetZoneID();
        m_uin = pSession->GetUIN();
    }
    else
    {
        m_iClientSessionID = INVALID_ID;

        return -1;
    }

    return 0;
}

NFSession* NFTransAccBase::GetClientSession() const
{
    return NFSessionUtil::GetSessionObj(m_iClientSessionID);
}

std::string NFTransAccBase::DebugString() const
{
    std::string log = NFTransBase::DebugString();
    log += " ZoneID:" + std::to_string(m_zoneId);
    log += " UIN:" + std::to_string(m_uin);
    NFSession* pSession = GetClientSession();
    if (pSession)
    {
        log += " SessionInfo:" + pSession->GetDebugInfo();
    }
    return log;
}

